<?
class bjUtil{
	
	static function getThemeRoot(){
		return 'themes/'.sfConfig::get('bj_theme_name').'/';
	}
	
    static function loadFile($filename){
    	return bjUtil::getThemeRoot().$filename;
    }    
    
    /**
     * Prints out the contents of an array into a human-readable format.
     * @param array An array to print.
     */
    static public function printArray($arr){
        Util::displayMessage("<pre>".print_r($arr, true)."</pre>");
    }

    /**
     * Prints out the methods of an object into a human-readable format.
     * @param object An object to print.
     */
    static public function printMethods($obj)
    {
        $arr = get_class_methods(get_class($obj));
        bjUtil::displayMessage("<pre>".print_r($arr, true)."</pre>");
    }   
   
    /**
     * Prints out a message.
     * @param string Message to print.
     * @param boolean If true, signals an exit call.
     */
    static public function displayMessage($msg, $quit=false){
        $box = '<div style="background-color: #363428; border: 1px solid #969271; font-family: Tahoma,Geneva,Verdana,Arial,Helvetica,sans-serif; color: #FFFFFF; padding: 10px;">';
       
        $box = $box.$msg;
       
        $box = $box.'</div>';
       
        echo $box;
        if($quit){
            exit;
        }   
    }        
    
    /**
     * Executes callbacks.
	 * @param array $params
	 * @subparam String [$params:->[i]->className] Class (with method name) to call before save
	 * @subparam String [$params:->[i]->methodName] 
	 * @subparam array Data to pass to the callbacks. 
	 * @return array
	 */
    static public function doCallback($callback, $data){
    	foreach($callback as $c){
	    	$data = call_user_func(array($c["className"], $c["methodName"]), $data);		
    	}
    	
    	return $data;
    }

	/**
	 * Checks if a string contains a value. If it is null, use the specified default.
	 * @param string String to check for a value.
	 * @param string Value to use if string is null.
	 * @return string String or value if null.
	 */
	static public function nvl($str, $default){
		if($str == '' || $str == null){
			return $default;
		} else {
			return $str;
		}
	}

	/**
	 * Converts a PHP array to XML
	 * @param XMLWriter
	 * @param array PHP array with values
	 * @return string The PHP array represented as XML
	 */	
	static public function ArrayToXML(XMLWriter $xml, $data){
	    foreach($data as $key => $value){
	        if(is_array($value)){
	            $xml->startElement($key);
	            $xml->xmlwriter_write_cdata($xml, $value);
	            $xml->endElement();
	            continue;
	        }
	        $xml->startElement($key);
	        $xml->writeCData($value);
	        $xml->endElement();
	    }
	}	

    
}

?>